<?php
header("Access-Control-Allow-Origin:*");
/*
参数:
cid //课时名称
uid //学生编号
*/
require_once '../../dz_framework/init.php';
$hid  = isset($_REQUEST['hid']) ? $_REQUEST['hid']:'';
$user_id  = isset($_REQUEST['uid']) ? $_REQUEST['uid']:'';
$exam_info = DB::fetch_first("select * from ".DB::table('teacher_exam_homework')." where h_id='".$hid."'");

if( empty($exam_info) )
{
	$result = array('flag'=>0,
				    'message'=> "未找到该课时的相关信息"
				);
	echo json_encode($result); die();
}
$item_content = unserialize($exam_info['content']);
	$all_count_question = 0;
	$question_info = '';
		foreach ($item_content as $key=>$value)
		{
			$sing_question = '';
			foreach ( $value as $k=>$v)
			{
				$sign_question = DB::fetch_first("select * from ".DB::table('study_item')." where tid='".$k."'");
				$sing_question['tid'] = $sign_question['tid'];
				$sing_question['name'] = preg_replace("/\[image\]([^\[]+)\[\/image\]/", "<img src=\"$1\">", $sign_question['title']);
				//$item_content[$key][$k]['item_content'] = $sign_question['item_content'];
				$sing_question['daan'] = $sign_question['daan'];
				$sing_question['type'] = $sign_question['type'];
				$sing_question['scores'] = $v['scores'];
				$choice = unserialize($sign_question['item_content']);
				$choice_news = '';
				foreach ( $choice as $kk=>$vv)
				{
					$choice_news[] = preg_replace("/\[image\]([^\[]+)\[\/image\]/", "<img src=\"$1\">", $vv);
				}
				$sing_question['choice'] = $choice_news;	
				$question_info[] = $sing_question;
			}
			
		}
$news_item_content['hid'] = $exam_info['h_id'];
$news_item_content['name'] = $exam_info['name'];
$news_item_content['description'] = $exam_info['description'];
$news_item_content['time_out'] = $exam_info['time_out'];
$news_item_content['total_fen'] = $exam_info['total_fen'];
$news_item_content['dateline'] = $exam_info['dateline'];
$news_item_content['user_id'] = $exam_info['user_id'];
$news_item_content['questions'] = $question_info;

$check_exam = DB::result_first("select user_id from ".DB::table('student_exam')." where h_id='".$exam_info['h_id']."' and user_id='".$user_id."'");
if($check_exam)
{
	$news_item_content['status'] = 	1;
}else{
	$news_item_content['status'] = 	0;
}
//print_r($news_item_content);exit;
echo json_encode($news_item_content); die();

//$array = array('0' => "Eric", '1' => array('test'=>111,'ex'=>'test'));   echo json_encode($array);
